package com.yanqu.road.server.cmd.activity.zhenhuan.second;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ZhenHuanProto;
import com.yanqu.road.pb.player.PlayerProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.activity.ActivityMgr;
import com.yanqu.road.server.manager.activity.zhenhuan.CrossZhenHuanConfigMgr;
import com.yanqu.road.server.manager.activity.zhenhuan.CrossZhenHuanMgr;
import com.yanqu.road.server.manager.activity.zhenhuan.CrossZhenHuanSecondActivity;
import com.yanqu.road.server.manager.activity.zhenhuan.CrossZhenHuanThirdProcessActivity;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.protocol.Protocol;

import java.math.BigInteger;

@Cmd(code = Protocol.C_CROSS_ZHENHUAN_PROMOTION_LIST_SYNC, desc = "游戏服上传的阶段的晋升名单")
public class CrossZhenHuanPromotionListSyncCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        ZhenHuanProto.CrossZhenHuanPromotionListSyncMsg reqMsg = ZhenHuanProto.CrossZhenHuanPromotionListSyncMsg.parseFrom(packet.getBytes());
        CrossZhenHuanThirdProcessActivity thirdProcessActivity = CrossZhenHuanMgr.getThirdProcessActivity(reqMsg.getActivityId());

        CrossZhenHuanSecondActivity secondActivity = CrossZhenHuanMgr.getSecondActivity(reqMsg.getActivityId());

        for (ZhenHuanProto.ZhenHuanPromotionTemp promotionTemp : reqMsg.getPromotionListList()) {
            UserBaseInfo userBaseInfo = PlayerBasePb.parseBaseUserInfo(promotionTemp.getUserBaseInfo());
            CrossUserMgr.updateUserBaseInfo(promotionTemp.getUserId(), userBaseInfo);

            if (thirdProcessActivity != null) {
                thirdProcessActivity.initUserData(promotionTemp.getUserId(), new BigInteger(promotionTemp.getValue()), promotionTemp.getParam(), promotionTemp.getLastUpdateTime());
            }
            if (secondActivity != null) {
                secondActivity.initUserData(promotionTemp.getUserId(), 1, 0);
            }
        }
    }

    @Override
    public void sendData() {

    }
}
